<template>
    <div>
        <h2>申请餐厅入驻</h2>
        <div id="login_form">
            <el-form :model="zhuceRestaurantForm" ref="ruleForm"  :rules="editRules" label-width="85px" class="demo-ruleForm">
                <el-form-item label="上传头像"  prop="url"  >
                    <el-upload
                            class="avatar-uploader"
                            action="http://192.168.1.37:7000/upload/upload"
                            :show-file-list="false"
                            :on-success="handleAvatarSuccess"
                    >
                        <img v-if="zhuceRestaurantForm.url" :src="zhuceRestaurantForm.url" class="avatar">
                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                    </el-upload>
                </el-form-item>

                <el-form-item label="餐厅名" label-width="85px" prop="restaurantname">
                    <el-input  v-model="zhuceRestaurantForm.restaurantname" autocomplete="off" onkeyup="this.value=this.value.replace(/\s+/g,'')"></el-input>
                </el-form-item>
                <el-form-item label="地址" label-width="85px" prop="address">
                    <el-input v-model="zhuceRestaurantForm.address" autocomplete="off" onkeyup="this.value=this.value.replace(/\s+/g,'')"></el-input>
                </el-form-item>

                <el-form-item label="餐厅描述" label-width="85px" prop="remark">
                    <el-input v-model="zhuceRestaurantForm.remark" autocomplete="off" onkeyup="this.value=this.value.replace(/\s+/g,'')"></el-input>
                </el-form-item>
                <el-form-item label="餐厅电话" label-width="85px" prop="phone">
                    <el-input v-model="zhuceRestaurantForm.phone" autocomplete="off" onkeyup="this.value=this.value.replace(/\s+/g,'')"></el-input>
                </el-form-item>
                <el-form-item>
            <span >
                <el-button @click="reback">取 消</el-button>
                <el-button type="primary" @click="goshen">确 定</el-button>
            </span>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
    export default {
        name: "Open",
        data(){
            return{
                zhuceRestaurantForm:{},
                //编辑商品校验规则
                editRules: {
                    url:[
                        {required: true, message: '请设置头像', trigger: 'blur'},
                    ],
                    restaurantname: [
                        {required: true, message: '请设置用户名', trigger: 'blur'},
                    ],
                    address: [
                        {required: true, message: '请输入地址', trigger: 'blur'},
                    ],
                    remark: [
                        {required: true, message: '请输入餐厅描述', trigger: 'blur'},
                    ],
                }
            }
        },
        methods:{
            //添加用户头像成功后触发的函数
            handleAvatarSuccess(res, file) {
                this.zhuceRestaurantForm.url = res.data;
            },
            //取消按钮
            reback(){
                this.$router.push("/index/my");
            },

            //餐厅审核
            goshen(){
                this.$http.post("/businessman/businessman/insertBusinessman",this.zhuceRestaurantForm).then(result=>{
                  console.log(result)
                    if (result.data.code==2000){
                      this.$message.success(result.data.msg);
                      this.$router.push("/index/my");
                  }
                });
            },
        },
    }
</script>

<style scoped>

</style>